home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / util / startup.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  104 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import platform
  5. import os.path as os
  6. from logging import getLogger, StreamHandler
  7. log = getLogger('startup')
  8. log.addHandler(StreamHandler())
  9. _myplatform = platform.platform(terse = True).split('-')[0]
  10.  
  11. def enable(program_path, nice_name, *args):
  12.     func_name = 'enable_' + _myplatform
  13.     if not nice_name:
  14.         pass
  15.     program_name = app_name(program_path)
  16.     globals()[func_name](program_path, program_name, *args)
  17.     log.info('%s will launch on startup', program_name)
  18.  
  19.  
  20. def disable(program_name):
  21.     func_name = 'disable_' + _myplatform
  22.     globals()[func_name](program_name)
  23.     log.info('%s removed from startup', program_name)
  24.  
  25.  
  26. def is_enabled(program_name):
  27.     return globals()['is_enabled_' + _myplatform]()
  28.  
  29.  
  30. def app_name(program_path):
  31.     return os.path.split(program_path)[-1].split('.')[0]
  32.  
  33.  
  34. def enable_Darwin(program_path, program_name, *args):
  35.     username = os.environ.get('USER')
  36.     home = os.environ.get('HOME')
  37.     folderpath = home + '/Library/LaunchAgents'
  38.     plistpath = home + '/Library/LaunchAgents/%(program_name)s.plist' % locals()
  39.     if not os.path.isdir(folderpath):
  40.         os.mkdir(folderpath)
  41.     
  42.     if not os.path.isfile(plistpath):
  43.         contents = '<?xml mersion="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple Computer//DTDPLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n    <key>Label</key>\n    <string>%(program_name)s</string>\n        <key>OnDemand</key>\n        <true/>\n        <key>ProgramArguments</key>\n            <array>\n                <string>%(program_path)s</string>\n' % locals()
  44.         contents += ''.join((lambda .0: for arg in .0:
  45. '<string>%s</string>' % arg)(args)) + '\n            </array>\n        <key>RunAtLoad</key>\n        <true/>\n        <key>ServiceDescription</key>\n        <string>This plist launches a the specified program at login.</string>\n        <key>UserName</key>\n        <string>%(username)s</string>\n    </dict>\n</plist>\n' % locals()
  46.         f = open(plistpath, 'w')
  47.         f.writelines(contents)
  48.         f.close()
  49.     else:
  50.         log.warning('There is already a startup item')
  51.  
  52.  
  53. def disable_Darwin(program_name):
  54.     home = os.environ.get('HOME')
  55.     plistpath = home + '/Library/LaunchAgents/%(program_name)s.plist'
  56.     if os.path.isfile(plistpath):
  57.         os.remove(plistpath)
  58.     else:
  59.         log.warning('There was no plist file to remove!')
  60.  
  61.  
  62. def is_enabled_Darwin(program_name):
  63.     home = os.environ.get('HOME')
  64.     path = home + '/Library/LaunchAgents/%s.plist' % program_name
  65.     return os.path.isfile(path)
  66.  
  67.  
  68. def _startup_regkey():
  69.     import _winreg as _winreg
  70.     return _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run', 0, _winreg.KEY_ALL_ACCESS)
  71.  
  72.  
  73. def enable_Windows(program_path, program_name, *args):
  74.     import _winreg
  75.     key = _startup_regkey()
  76.     regval = program_path + ' ' + ' '.join(args)
  77.     _winreg.SetValueEx(key, program_name, 0, _winreg.REG_SZ, regval)
  78.     _winreg.CloseKey(key)
  79.  
  80.  
  81. def disable_Windows(program_name):
  82.     import _winreg
  83.     key = _startup_regkey()
  84.     
  85.     try:
  86.         _winreg.DeleteValue(key, program_name)
  87.     except WindowsError:
  88.         log.warning('startup.disable could not delete registry key')
  89.  
  90.     _winreg.CloseKey(key)
  91.  
  92.  
  93. def is_enabled_Windows(program_name):
  94.     import _winreg
  95.     key = _startup_regkey()
  96.     
  97.     try:
  98.         _winreg.QueryValueEx(key, program_name)
  99.         return True
  100.     except WindowsError:
  101.         return False
  102.  
  103.  
  104.